<div id="breadcrumb">
    <a onclick="javascript:history.go(-1);" class="go-to-home tip-bottom font font18" style="cursor: pointer;">
        <i class="icon-arrow-left"></i> 返回 &nbsp;
    </a>
    <a onclick="javascript:history.go(-1);" class="font font18" style="cursor: pointer;"> &nbsp;&nbsp;<span>代理 &gt</span></a>
    <a onclick="javascript:history.go(-1);" class="font font18" style="cursor: pointer;"> <span>家族&gt</span></a>
    <a href="/agent/familyinfo?id={{info['id']}}" class="current font font18"> <span>家族详情</span></a>
    <input type="hidden" id="familyId" value="{{info['id']}}">
</div>

<!--sidebar-menu-->
<div id="sidebar" class="clearfix">
    <div class="user-info">
        <img alt="" src="{{info['logo']}}">

        <p>
            <span class="font font20 cr-dpe">{{info['name']}}</span>
        </p>
    </div>
    <div class="progtrckr-box">
        <div class="progtrckrline" style="height: 192px;"></div>
        <ul class="progtrckr">
            <li ><i class="custom-icon custom-icon-point"></i><a href="/agent/familyinfo?id={{info['id']}}">基本资料</a></li>
            <li class="active"><i class="custom-icon custom-icon-point"></i><a href="/agent/familyanchor?id={{info['id']}}">旗下主播</a></li>
            <li><i class="custom-icon custom-icon-point"></i><a href="/agent/familyincome?id={{info['id']}}">收益</a></li>
            <li><i class="custom-icon custom-icon-point"></i><a href="/agent/familytrend?id={{info['id']}}">趋势分析</a></li>
        </ul>
    </div>
</div>
<!--end sidebar-menu-->

<div id="applyinfo_content" style="  margin-left: 230px;">
    <div class="container-fluid" style="padding: 0;">
        <div class="widget-box tab-tabs" >
            <div class="widget-title">

            </div>
            <div class="widget-content tab-content">
                <div id="tab1" class="tab-pane active">
                    <div class="container-fluid">
                        <div class="row-fluid" style="margin: 20px 0;overflow: hidden;">

                        </div>
                        <div class="row-fluid" style="border: 1px solid #ddd;font-size: 16px;margin-bottom: 20px;">
                            <div style="height: 50px;color: #817CCE;line-height: 50px;border-bottom: 2px solid #ddd;margin: 0 20px;">导出旗下所有主播在一段时间内的工作情况，导出excel</div>
                            <div style="height:50px;margin: 10px 20px 0;">
                                <span>请选择起止日期</span>
                                <a class="date-calendar " style="margin-left: 8px;"><i class=" icon-calendar"></i> <input id="mydate"  placeholder="请输入日期"  value="" style="height: 34px;"></a>
                                <form action="/ajax/excelData" method="post" style="margin: -36px 0 0 330px;" onsubmit="return exceldataSubmit()">
                                    <input type="hidden" value="{{info['id']}}" name="familyId">
                                    <input type="hidden" value="" name="startTime" id="_startTime">
                                    <input type="hidden" value="" name="endTime" id="_stopTime">
                                    <button  type="submit" class="btn btn-purple">导出表格</button>
                                </form>
                            </div>
                        </div>
                        <div class="row-fluid">
                            <table id="tableList" class="table with-check table-purple">
                                <thead>
                                <tr>
                                    <th>主播号</th>
                                    <th>昵称</th>
                                    <th>主播等级&uarr;&darr;</th>
                                    <th class="cursor" onclick="tableOrderClick('fiamlyform',1,familylist)">粉丝&uarr;&darr;</th>
                                    <th class="cursor" onclick="tableOrderClick('fiamlyform',1,familylist)">为家族创造收益（聊币）&uarr;&darr;</th>
                                    <th></th>
                                </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                        </div>

                        {% include "common/pagination.html" %}
                    </div>
                </div>


            </div>
        </div>

    </div>
</div>
<script src="{{static_url('web/js/daterangepicker.jQuery.js')}}"></script>
<link rel="stylesheet" href="{{static_url('web/css/ui.daterangepicker.css')}}">
<script type="text/javascript">

    $(function(){
        $('body').addClass('anchorinfo');

        getDataList();

        $('#mydate').daterangepicker({
                    presetRanges:[
                        //{text:'最近一周', dateStart:'yesterday-7days', dateEnd:'yesterday' },
                        //{text:'最近一月', dateStart:'yesterday-1month', dateEnd:'yesterday' },
                        //{text:'最近一年', dateStart:'yesterday-1year', dateEnd:'yesterday' }
                    ],
                    presets:{
                        dateRange:'自定义时间'
                    },
                    rangeStartTitle:'起始日期',
                    rangeEndTitle:'结束日期',
                    nextLinkText:'下月',
                    prevLinkText:'上月',
                    doneButtonText:'确定',
                    cancelButtonText:'取消',
                    earliestDate:'',
                    latestDate:Date.parse('today'),
                    constrainDates:true,
                    rangeSplitter:'-',
                    dateFormat:'yy-mm-dd',
                    closeOnSelect:false,
                    onOpen:function(){
                        $('.ui-daterangepicker-dateRange').click().parent().hide();
                        $('.ui-daterangepickercontain').css({left:($('#mydate').offset().left-120)+'px'});
                    },
                    onClose:function(){
//                        var typer=$('#mydate').attr('data');
                        var b=$('#mydate').val();
                        var timeBegin= b.substring(0,10);
                        var timeEnd= b.substring(12,23);
                        $('#_startTime').val(timeBegin);
                        $('#_stopTime').val(timeEnd);

                    }
                }
        );
    });

    function exceldataSubmit(){
        var start=$('#_startTime').val();
        var end=$('#_stopTime').val();
        if(start==''&& end=='')
        {
            alert('请选择时间');
            return false;
        }
        else if(start==''){
            alert('请选择时间');
            return false;
        }
        else{
            return true;
        }
    }

   function getDataList(index){
       var data={};
       data.page=index||1;
       data.pageSize=global.pageSize;
       data.familyId=$('#familyId').val();

       $.ajax({
           type:"POST",
           data:data,
           url:'/ajax/familyAllAnchor',
           dataType:'json',
           success:function(res){
               var data=res.data;
               var tableList=document.getElementById("tableList");
               var tbody= tableList.getElementsByTagName('tbody')[0];
               dataTable.clearData(tbody);

               var count=document.getElementById('count');
               count.innerHTML=data.data.count;

               for(var i=0;i<data.data.list.length;i++){
                   addRow(tbody,data.data.list[i]);
               }
               if(!index||index==0){
                   utilsPagination("#pagination",data.data.count,global.pageSize,function(page_index,jq){
                       page_index+=1;
                       getDataList(page_index);
                   });
               }
           }
       });
   }

    function addRow(table,data){
        var row=table.insertRow();
        var cell=row.insertCell(0);
        var cell1=row.insertCell(1);
        var cell2=row.insertCell(2);
        var cell3=row.insertCell(3);
        var cell4=row.insertCell(4);
        var cell5=row.insertCell(5);

        var div=document.createElement("div"),
                img=document.createElement("img"),
                span=document.createElement("span");

        div.className="anchor-info";
        img.src=global.contract+data.avatar;
        span.innerHTML=data.uid;

        div.appendChild(img);
        div.appendChild(span);

        cell.appendChild(div);

        cell1.innerHTML=data.nickName;
        cell2.innerHTML=data.level2;
        cell3.innerHTML=data.fans;
        cell4.innerHTML=data.income;
        /*var a=document.createElement("a");
        a.href='/anchor/anchorinfo?uid='+data.uid;
        a.innerHTML="查看";
        a.className="a-edit font font18 cr-pe cursor-pointer";
        cell5.appendChild(a);*/
        cell5.innerHTML='<span class="spanedit"><a class="cursor-pointer" onclick="delAnchor('+data.uid+') ">从家族中删除</a>&nbsp;|&nbsp;<a href="/anchor/anchorinfo?uid='+data.uid+'" >查看</a></span>';
        return row;
    }

    function delAnchor(id){
        if(confirm('确定从家族中删除该主播？')){
            var data = {};
            data.uid = id;
            $.ajax({
                type : "POST",
                data : data,
                url : '/ajax/delAnchor',
                dataType : 'json',
                success : function (res) {
                    if(res.code == 0) {
                        location.reload();
                    }else{
                        alert(res.info);
                    }
                }
            })
        }
    }
</script>